package Repositorio;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RepositorioPlano {
	private Statement stmt;
	private String sqlStatement;
	public RepositorioPlano() {
		stmt = Conexao.getInstance().stmt;
	}
	public void cadastrarPlano(String plano) throws SQLException {
		sqlStatement = "INSERT INTO Plano VALUES('"+plano+"')";
		stmt.executeUpdate(sqlStatement);
	}
	public void removerPlano(String plano) throws SQLException {
		sqlStatement = "DELETE FROM Plano WHERE Nome='"+plano+"'";
		stmt.executeUpdate(sqlStatement);
	}
	public String[] consultarPlano() throws SQLException {
		ResultSet rs;
		sqlStatement = "SELECT count(*) FROM Plano";
		rs = stmt.executeQuery(sqlStatement);
		rs.next();
		int especialLength = rs.getInt("count(*)");
		String Plano[] = new String[especialLength];
		sqlStatement = "SELECT Nome FROM Plano";
		rs = stmt.executeQuery(sqlStatement);
		int i = 0;
		while(rs.next()) {
			Plano[i] = rs.getString("Nome");
			i++;
		}
		return Plano;
	}
	public boolean verificarPlano(String plano) throws SQLException {
		boolean ret;
		sqlStatement = "SELECT * FROM Plano WHERE Nome='"+plano+"'";
		ResultSet rs = stmt.executeQuery(sqlStatement);
		if(rs.next()) {
			ret = true;
		} else {
			ret = false;
		}
		return ret;
	}
};
